package com.hhkj.admin.order.common.component.validator;

import com.hhkj.admin.course.domain.CoursePriceConf;
import com.hhkj.admin.order.common.exception.InvalidOrderItemException;
import com.hhkj.admin.order.domain.OrderItem;
import lombok.AllArgsConstructor;

import java.util.List;
import java.util.Map;

@AllArgsConstructor
public class SysCoursePriceValidateStrategy extends BaseOrderItemValidateStrategy{

    /**（科目父级id-科目价格信息）map映射表 **/
    private Map<Long, List<CoursePriceConf>> coursePriceMap;

    /** (科目id-科目父级id)map映射表 **/
    private Map<Long, Long> courseIdParentIdMap;

    /**
     * 校验期限和学员单价
     * @param orderItem
     * @return
     * @throws InvalidOrderItemException
     */
    @Override
    public boolean validate(OrderItem orderItem) throws InvalidOrderItemException {
        Long parentId = courseIdParentIdMap.get(orderItem.getCourseId());
        List<CoursePriceConf> coursePriceConfList = coursePriceMap.get(parentId);
        Long coursePriceId = OrderItemValidator.isValidDayAmountAndPrice(orderItem, coursePriceConfList);
        orderItem.setCoursePriceId(coursePriceId);
        return true;
    }
}
